package adv.i31.robot;

import android.media.audiofx.AudioEffect.OnEnableStatusChangeListener;
import android.opengl.GLES20;

public class FragmentShader {

	public int getFragmentShaderHandle() {
		return fragmentShaderHandle;
	}

	public void setFragmentShaderHandle(int fragmentShaderHandle) {
		this.fragmentShaderHandle = fragmentShaderHandle;
	}

	private int fragmentShaderHandle;

	public FragmentShader(final String code) {
		fragmentShaderHandle = GLES20.glCreateShader(GLES20.GL_FRAGMENT_SHADER);
		if (fragmentShaderHandle != 0) {
			GLES20.glShaderSource(fragmentShaderHandle, code);
			GLES20.glCompileShader(fragmentShaderHandle);

			final int[] compileStatus = new int[1];
			GLES20.glGetShaderiv(fragmentShaderHandle, GLES20.GL_COMPILE_STATUS, compileStatus, 0);

			if (compileStatus[0] == 0) {
				GLES20.glDeleteShader(fragmentShaderHandle);
				fragmentShaderHandle = 0;
			}
		}

		if (fragmentShaderHandle == 0) {
			throw new RuntimeException("Error creating fragment shader.");
		}
	}
}
